//
//  ChaseBookHeadView.m
//  WNZSSQ
//
//  Created by JDKJ on 2018/12/6.
//  Copyright © 2018年 JDKJ. All rights reserved.
//

#import "ChaseBookHeadView.h"

@interface ChaseBookHeadView ()<WLScrollViewDelegate>

@end

@implementation ChaseBookHeadView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        WLScrollView *wls = [[WLScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 110)];
        wls.isAnimation = NO;
        wls.delegate = self;
        wls.scale = 1;
        wls.marginX = 0;
        wls.backgroundColor = [UIColor clearColor];
        [wls starRender];
        [self addSubview:wls];
        self.wlScrollView = wls;
        
        
        //页码
        UIPageControl * page = [[UIPageControl alloc]init] ;
        //设置背景颜色
        page.backgroundColor = CSWhiteColor;
        //设置小圆圈的个数
        page.numberOfPages = 5;
        //设置 小圆圈的颜色
        page.pageIndicatorTintColor = CSColorFromRGB(0xDCDCDC);
        
        //设置当前页的小圆圈颜色
        page.currentPageIndicatorTintColor = CSColorFromRGB(0xF95C48);
        page.userInteractionEnabled = NO;
        //获取/更改当前页
        page.currentPage = 0;
        [self addSubview:page];
        self.page = page;
        
        /**
         分割线
         */
        UIView * sepView = [[UIView alloc]init];
        sepView.backgroundColor = CSColorFromRGB(0xF5F5F5);
        [self addSubview:sepView];
        self.sepView = sepView;
        
        [self setConstraints];
        
    }
    return self;
    
}

-(void)setConstraints
{
    //设置约束条件
    
    //滚动
    [self.wlScrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.width.mas_equalTo(self);
        make.height.mas_equalTo(110);
        
    }];
    
    //页码
    [self.page mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.width.mas_equalTo(self);
        make.top.mas_equalTo(self.wlScrollView.mas_bottom).offset(5);
        
    }];
    
    /**
     分割线
     */
    [self.sepView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.page.mas_bottom).offset(5);
        make.left.bottom.width.mas_equalTo(self);
        make.height.mas_equalTo(10);
        
    }];
}

#pragma mark - WLScrollViewDelegate

- (NSInteger)numOfContentViewScrollView:(WLScrollView *)scrollView{
    return 5;
}

- (WLSubView *)scrollView:(WLScrollView *)scrollView subViewFrame:(CGRect)frame cellAtIndex:(NSInteger)index{
    
    static NSString *cellID = @"123";
    
    CycleScrollView *custView = (CycleScrollView *)[scrollView dequeueReuseCellWithIdentifier:cellID];
    
    if (!custView) {
        custView = [[CycleScrollView alloc] initWithFrame:frame Identifier:cellID];
    }
    
    return custView;
    
}

- (void)scrollView:(WLScrollView *)scrollView didSelectedAtIndex:(NSInteger)index{
    NSLog(@"点击 index %zd",index);
}

- (void)scrollView:(WLScrollView *)scrollView didCurrentCellAtIndex:(NSInteger)index{
    NSLog(@"现在显示的 index %zd",index);
    
    self.page.currentPage = index;
}

@end

#pragma mark - 尾部

@implementation ChaseBookfToolView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        
        /**
         add
         */
        UIImageView *addImageView = [[UIImageView alloc]init];
        addImageView.image = [UIImage imageNamed:@"添加喜欢小说"];
        addImageView.contentMode = UIViewContentModeScaleAspectFill;
        addImageView.clipsToBounds = YES;
        self.addImageView = addImageView;
        [self addSubview:addImageView];
        
        /**
         书名
         */
        UILabel *addLikeLable = [[UILabel alloc]init];
        addLikeLable.text = @"添加喜欢的小说";
        addLikeLable.textColor = CSColorFromRGB(0x6B6763);
        addLikeLable.font = SmallFont;
        self.addLikeLable = addLikeLable;
        [self addSubview:addLikeLable];
        
        
        [self setConstraints];
        
    }
    return self;
    
}

-(void)setConstraints
{
    //设置约束条件
    
    /**
     add
     */
    [self.addImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(self);
        make.centerY.mas_equalTo(self).offset(-20);
        
    }];
    
    [self.addLikeLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.addImageView.mas_bottom).offset(10);
        make.centerX.mas_equalTo(self);
        
    }];
    
    
}


@end

#pragma mark - cell

@implementation ChaseBookcell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        //封面
        UIImageView *covImageView = [[UIImageView alloc]init];
        covImageView.image = PlaceHold5;
        covImageView.contentMode = UIViewContentModeScaleAspectFill;
        covImageView.clipsToBounds = YES;
        self.covImageView = covImageView;
        [self addSubview:covImageView];
        
        //书名
        UILabel *titleLable = [[UILabel alloc]init];
        titleLable.text = @"花生中含有大";
        titleLable.textColor = CSBlackColor1;
        titleLable.font = kFont15;
        self.titleLable = titleLable;
        [self addSubview:titleLable];
        
        /**
         上次更新
         */
        UILabel *upDateLable = [[UILabel alloc]init];
        upDateLable.text = @"上次读到第30章";
        upDateLable.textColor = CSColorFromRGB(0x6B6763);
        upDateLable.font = kFont11;
        self.upDateLable = upDateLable;
        [self addSubview:upDateLable];
        
        /**
         最近更新更新
         */
        UILabel *nesUpDateLable = [[UILabel alloc]init];
        nesUpDateLable.text = @"10月21日更新到32章";
        nesUpDateLable.textColor = CSColorFromRGB(0x6B6763);
        nesUpDateLable.font = SmallFont;
        self.nesUpDateLable = nesUpDateLable;
        [self addSubview:nesUpDateLable];
        
        /**
         添加按钮
         */
        
        UIButton *delBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [delBtn setImage:[UIImage imageNamed:@"删除书架"] forState:UIControlStateNormal];
        delBtn.contentEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10);
        [self addSubview:delBtn];
        self.delBtn = delBtn;
        
        [self setConstraints];
        
    }
    return self;
}

-(void)setConstraints
{
    //设置约束条件
    
    /**
     封面
     */
    [self.covImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self).offset(15);
        make.left.mas_equalTo(self).offset(13);
        make.width.mas_equalTo(45);
        make.height.mas_equalTo(60);
        make.bottom.mas_equalTo(self).offset(-15);
        
    }];
    
    //书名
    [self.titleLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(self.upDateLable.mas_top).offset(-9);
        make.left.mas_equalTo(self.covImageView.mas_right).offset(13);
        make.right.mas_lessThanOrEqualTo(self.delBtn.left).offset(-10);
        
    }];
    
    
    /**
     上次更新
     */
    [self.upDateLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.covImageView);
        make.left.mas_equalTo(self.covImageView.mas_right).offset(13);
        make.right.mas_lessThanOrEqualTo(self.delBtn.left).offset(-10);
        
    }];
    
    /**
     最近更新更新
     */
    [self.nesUpDateLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.upDateLable.mas_bottom).offset(6);
        make.left.mas_equalTo(self.covImageView.mas_right).offset(13);
        make.right.mas_lessThanOrEqualTo(self.delBtn.left).offset(-10);
        
    }];
    
    /**
     删除
     */
    [self.delBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.covImageView);
        make.right.mas_equalTo(self).offset(-13);
        
    }];
    
    
}



@end
